package com.umeox.watch.moto.dataservice.work;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import com.alibaba.fastjson.JSONObject;
import com.umeox.moto.common.log.Logger;
import com.umeox.watch.moto.dataservice.base.BaseApp;
import com.umeox.watch.moto.dataservice.services.ApiService;

import java.util.Set;

/**
 * Created by Rambo 2021/12/6
 * Describe:
 */
public class UploadHotVerWork extends Worker {


    public static final String ATTRIBUTES = "attributes";

    public UploadHotVerWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {
        Set<String> attrSet = BaseApp.getInstance().getMmkv().decodeStringSet(ATTRIBUTES);
        if (attrSet != null && !attrSet.isEmpty()) {
            JSONObject jsonObject = new JSONObject();
            for (String key : attrSet) {
                jsonObject.put(key,BaseApp.getInstance().getMmkv().decodeLong(key));
            }
            Logger.i("UploadHotVerWork","需要上传的属性版本：" + jsonObject);
            ApiService.uploadHotVer(jsonObject);
        } else {
            Logger.e("UploadHotVerWork","没有需要上传的属性版本");
        }
        return Result.success();
    }
}
